home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14755 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  37 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Philippe Verdy <100105.3120@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is it OK to delete const *type pointers?
  5. Date: 1 Apr 1996 23:48:16 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4jpq00$lhj@dub-news-svc-6.compuserve.com>
  8. NNTP-Posting-Host: ad15-078.compuserve.com
  9.  
  10. jlilley@ix.netcom.com (John Lilley) s'Θcrit :
  11. > In article <4jhjub$fpc@mag1.magmacom.com>, ezust@mag1.magmacom.com says...
  12. > >Some compilers let me do this, others do not. What I would like to know is,
  13. > >what does Stroustrup think? I.e. is it written somewhere in the ARM (I checked
  14. > >but can't find it) or in the draft standard? If somoene could e-mail me a
  15. > >quote or a pointer to a place where I can read where it says such a thing
  16. > >should or should not be allowed, I would appreciate it!
  17. > >
  18. > >const int* array= new int[30];
  19. > >delete[] array;
  20. > The ARM says that it is valid to call the destructor for a const object.
  21. > This implies to me that it should also be legal to delete it.  However,
  22. > I cannot find that explicitly stated.
  23. > john lilley
  24. Yes it is OK: the object it self is not modifiable, for the
  25. whole time it lives only. They can be destructed when needed.
  26. Beeing const means you can modify the object somebody has created
  27. for you.
  28. However be careful when you delete that object: it may be
  29. still referenced by other aliased pointers (when passing the
  30. const object pointer to a function), so these references
  31. could become invalid. But the same warning exists on all
  32. pointers, and on all local objects allocated on the stack,
  33. would they be const or not...
  34.